package com.leancloud.home.fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.aries.ui.view.title.TitleBarView;
import com.leancloud.home.R;
import com.leancloud.home.adapter.HomeHotAdapter;
import com.leancloud.home.entity.ComputingEntity;
import com.vise.xsnow.event.BusManager;

import java.util.ArrayList;
import java.util.List;

import tech.com.commoncore.base.BaseTitleFragment;
import tech.com.commoncore.basecomponent.ServiceFactory;
import tech.com.commoncore.event.SwitchEvent;

public class HomeFragment extends BaseTitleFragment implements View.OnClickListener {


    HomeHotAdapter homeHotAdapter;
    private RecyclerView rvHomeHot;
    private LinearLayout ll_cep;
    TextView tv_zixun;
    TextView tv_zuhe;
    TextView tv_kuaixun;
    TextView tv_zjlx;
    public static HomeFragment newInstance() {
        Bundle args = new Bundle();
        HomeFragment fragment = new HomeFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText(getResources().getString(R.string.home_app_name));

    }

    @Override
    public int getContentLayout() {
        return R.layout.home_fragment_home1;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        rvHomeHot = (RecyclerView) mContentView.findViewById(R.id.rv);
        tv_zixun = (TextView) mContentView.findViewById(R.id.tv_zixun);
        tv_zjlx = (TextView) mContentView.findViewById(R.id.tv_zjlx);
        tv_zuhe = (TextView) mContentView.findViewById(R.id.tv_zuhe);
        tv_kuaixun = (TextView) mContentView.findViewById(R.id.tv_kuaixun);
        ll_cep = (LinearLayout) mContentView.findViewById(R.id.ll_cep);
        homeHotAdapter = new HomeHotAdapter(R.layout.home_item_hot);
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.HORIZONTAL);
        rvHomeHot.setLayoutManager(manager);
        rvHomeHot.setAdapter(homeHotAdapter);
        tv_zixun.setOnClickListener(this);
        tv_zuhe.setOnClickListener(this);
        ll_cep.setOnClickListener(this);
        tv_zjlx.setOnClickListener(this);
        tv_kuaixun.setOnClickListener(this);

        getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.ll_hot_zixun,ServiceFactory.getInstance().getZixunService().newGanTou(null)).commit();

        getDatas();

    }
    private void getDatas() {
        List<ComputingEntity> list = new ArrayList<>();
        list.add(new ComputingEntity("","",R.mipmap.home_b_1));
        list.add(new ComputingEntity("","",R.mipmap.hone_b_2));
        list.add(new ComputingEntity("","",R.mipmap.hone_b_3));
//        list.add(new ComputingEntity("","",R.mipmap.hone_b_4));
//        list.add(new ComputingEntity("","",R.mipmap.hone_b_5));
        list.add(new ComputingEntity("","",R.mipmap.hone_b_6));
        homeHotAdapter.setNewData(list);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.tv_zixun) {
//            ARouter.getInstance().build("/zixun/jingxuan").navigation();
            BusManager.getBus().post(new SwitchEvent(2));
        }
        if (id == R.id.ll_cep) {
            ARouter.getInstance().build("/evaluation/start").navigation();
        }
        if (id == R.id.tv_zuhe) {
            ARouter.getInstance().build("/hq/edite").navigation();
        }
        if (id == R.id.tv_kuaixun) {
            ARouter.getInstance().build( "/zixun/kuaixun").navigation();
        }
        if (id == R.id.tv_zjlx) {
            ARouter.getInstance().build( "/hq/zjlx").navigation();

        }
    }
}
